package de.slothsoft.wasbinich.core.util;

import java.text.MessageFormat;

import de.slothsoft.wasbinich.core.database.DatabaseException;
import de.slothsoft.wasbinich.core.database.DatabaseExceptionCode;

public final class ExceptionUtil {

    public static boolean isCancelledByUserException(Exception exception) {
	if (exception instanceof DatabaseException)
	    return ((DatabaseException) exception).getCode() == DatabaseExceptionCode.CANCELLED_BY_USER;
	return false;
    }

    public static String getErrorMessage(Exception exception) {
	if (exception instanceof DatabaseException)
	    return ((DatabaseException) exception).getCode().getMessage();
	return MessageFormat.format(Messages.getString("ExceptionUtil.baseMessage"), exception.getMessage()); //$NON-NLS-1$
    }

    private ExceptionUtil() {
	// hide me
    }

}
